
Character = PermanentGameelement:new{
	str = 0,
	agi = 0,
	int = 0,
	dex = 0,

	nativeStr = 0,
	nativeAgi = 0,
	nativeInt = 0,
	nativeDex = 0,

	skp = 0,
	level = 0,
	exp = 0,
	speed = 0,
	direction = 3,
	
	equipmentSlots = {
		head ="head",		
		leftHand = "hand",
		rightHand = "hand",
		body = "body", 
		hip = "belt", 
		legs = "legs", 
		feets = "feets"
	},

	stateList = {
		control = {
			name = 'control',
			actions = {
			-- -- -- -- -- -- -- --
			-- -- STATUSCHECK -- --   TODO: remove this to the right place
			-- -- -- -- -- -- -- --
			function (t)
		 		if t.hp <= 0 then t:changeState(t.stateList.dead) end
			 	if t.mana < t.manaMax then t:regenerateHp()end
			 	if t.hp < t.hpMax then t:regenerateHp()end
			 	if t.exp > t.level * 20 then t:levelUp() end
			end,

			-- -- -- -- -- -- -- --
			-- -- CONTROLS -- -- -- 
			-- -- -- -- -- -- -- --

			onButton1 = function(t)
					if controls.newPress.button1 then 
					 shootFirebal(t, 13, 50, t.direction,5)
				end
			end,

			onButton5 = function (t)
				if controls.newPress.button5 then
				t:meleAttack(gameelements) 
				end
			end,

			onButton6 = function (t)
				if controls.newPress.button6 then 
				end
			end,

			onUp = function (t)
			  if controls.held.up then
				t.direction = 1 --north
			  end
			end,

			onUpRight = function (t)
			  if controls.held.right and controls.held.up then
				t.direction = 5 --northeast
			  end
			end,

			onRight = function (t)
			  if controls.held.right then
				t.direction = 2 --east
			  end
			end,

			onDownRight = function (t)
			  if controls.held.right and controls.held.down then
				t.direction = 6 --southeast
			  end
			end,

			onDown = function (t)
			  if controls.held.down then
				t.direction = 3 --south
			  end
			end,

			onDownLeft = function (t)
			  if controls.held.down and controls.held.left then
				t.direction = 7 --southwest
			  end
			end,

			onLeft = function (t)
			  if controls.held.left then
				t.direction = 4 --west
			  end
			end,	

			onUpLeft = function (t)
			  if controls.held.left  and controls.held.up then
				t.direction = 8 --northwest
			  end
			end,
			function(t)
				if controls.held.right or controls.held.left or controls.held.down or controls.held.up then t:walk() else t.velocity ={0,0} end
			end
			}
		}
	},
	
		dead = {
			name = 'dead',
			actions = {
				function (t)
					t.currentState = t.stateList.destroy
					t:newOht("Tot!!",0.3,2)
				end
			}
		}
	
}

-- calculates the atributes of the Char instance, if available includes the Equipment
function Character:calculateAttributes( ) 

	self.str = self.nativeStr
	self.agi = self.nativeAgi
	self.int = self.nativeInt
	self.dex = self.nativeDex
	 
	if self.Equipment then
	local bonusTable = self:readEquipment()
		for k,v in pairs( self.inventory) do
			self[k] = self[k] + v
		end
	end
end

-- the character gests an level up
function Character:levelUp( ) 
	self.level = self.level + 1
	self.hp = self.hpMax
	self.mana = self.manaMax
	self.skp = self.skp + 5
end

function Character:walk()
	if self.direction == 1 then 
		self.velocity = {0,-self.movementSpeed}--north
	elseif self.direction == 2 then 
		self.velocity = {self.movementSpeed,0}--east
	elseif self.direction == 3 then 
		self.velocity = {0,self.movementSpeed}--south
	elseif self.direction == 4 then
	 	self.velocity = {-self.movementSpeed,0}--west
	elseif self.direction == 5 then 
		self.velocity = {self.movementSpeed,-self.movementSpeed}--northeast
	elseif self.direction == 6 then 
		self.velocity = {self.movementSpeed,self.movementSpeed}--southeast
	elseif self.direction == 7 then 
		self.velocity = {-self.movementSpeed,self.movementSpeed}--southwest
	elseif self.direction == 8 then 
		self.velocity = {-self.movementSpeed,-self.movementSpeed}--northwest
	else 
			self.velocity = {0,0}
	end	
end
-------------------------
--------------States-----
------------------------
--[[Character.stateList.control = {
		name = 'control',
		actions = {
		-- -- -- -- -- -- -- --
		-- -- STATUSCHECK -- --   TODO: remove this to the right place
		-- -- -- -- -- -- -- --
		function (t)--hero.statuscheck() -- basic, experience, health, mana, oht status check. nearly in every state avaible
	 		if t.hp <= 0 then t:changeState(t.stateList.dead) end -- TODO: changestate function
		 	if t.mana < t.manaMax then t:regenerateHp()end
		 	if t.hp < t.hpMax then t:regenerateHp()end
		 	if t.exp > t.level * 20 then t:levelUp() end
		end,

		-- -- -- -- -- -- -- --
		-- -- CONTROLS -- -- -- 
		-- -- -- -- -- -- -- --

		onButton1 = function(t)
				if controls.newPress.button1 then 
				 shootFirebal(t, 13, 50, t.direction,5)
			end
		end,
		
		onButton2 = function(t)
				if controls.newPress.button2 then 
				 shootFirebal(t, 13, 50, t.direction,5)
			end
		end,
		
		onButton3 = function(t)
				if controls.newPress.button3 then 
				 shootFirebal(t, 13, 50, t.direction,5)
			end
		end,
		
		onButton4 = function(t)
				if controls.newPress.button4 then 
				 shootFirebal(t, 13, 50, t.direction,5)
			end
		end,

		onButton5 = function (t)
			if controls.newPress.button5 then
			t:meleAttack(gameelements) 
			end
		end,

		onButton6 = function (t)
			if controls.newPress.button6 then 
			  teleport(t, 60)
			end
		end,

		onUp = function (t)
		  if controls.held.up then
			t.direction = 1 --north
		  end
		end,

		onUpRight = function (t)
		  if controls.held.right and controls.held.up then
			t.direction = 5 --northeast
		  end
		end,

		onRight = function (t)
		  if controls.held.right then
			t.direction = 2 --east
		  end
		end,

		onDownRight = function (t)
		  if controls.held.right and controls.held.down then
			t.direction = 6 --southeast
		  end
		end,

		onDown = function (t)
		  if controls.held.down then
			t.direction = 3 --south
			-- TODO: remove, just testing
			for _, gm in pairs(gameelements) do
				--gm:runAction("test", gm , 10)
		  end
		  end
		end,

		onDownLeft = function (t)
		  if controls.held.down and controls.held.left then
			t.direction = 7 --southwest
		  end
		end,

		onLeft = function (t)
		  if controls.held.left then
			t.direction = 4 --west
		  end
		end,	

		onUpLeft = function (t)
		  if controls.held.left  and controls.held.up then
			t.direction = 8 --northwest
		  end
		end,
		function(t)
			if controls.held.right or controls.held.left or controls.held.down or controls.held.up then t:walk() end
		end
		}
}
]]			

dofile('itemsystem.lua')
dofile('enemy.lua')
dofile('hero.lua')
